package com.jucat.response;

import com.jucat.enums.CodeEnum;
import lombok.Data;

/**
 * 接口统一的响应格式
 * @author manem
 * @param <T> 响应数据
 */
@Data
public class Result<T>{
    private int code;
    private String msg;
    private T data;

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(CodeEnum code, T data) {
        this(code.getCode(), code.getMsg(), data);
    }

    public Result(CodeEnum code) {
        this(code.getCode(), code.getMsg(), null);
    }

    public static <T>Result<T> ok(T data) {
        return new Result<>(CodeEnum.OK, data);
    }

    public static <T>Result<T> err() {
        return new Result<>(CodeEnum.ERR);
    }

    public static <T>Result<T> err(CodeEnum code) {
        return new Result<>(code);
    }
}
